<?php
if (isset($_POST['op']) &&  isset($_POST['id']) ){
    include 'config.php';
    $openid=$_POST['op'];
    $id=(int)$_POST['id'] + 1;
    $mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
    $query=$mysqli->query("SELECT msg FROM isread where openid='".$openid."' limit 0,1 ");
    if($query->num_rows>0){
        $data=$query->fetch_assoc();
        $msg=json_decode($data['msg'],true);
        $msg[]=$id;
        $mysqli->query("update isread set msg='".json_encode($msg)."',createtime='".date("Y-m-d H:i:s")."' where openid='".$openid."'  ");
    }else{
        $msg=array();
        $msg[]=$id;
        $mysqli->query("insert into isread(openid,msg,createtime) values('".$openid."','".json_encode($msg)."','".date("Y-m-d H:i:s")."')  ");
    }
    $mysqli->close();
    echo json_encode(array('s'=>1));
}else{
    echo json_encode(array('s'=>666));
}

